﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CombatText : MonoBehaviour
{
    [SerializeField]
    private float moveSpeed,lifeTime;
    [SerializeField]
    private Text text;
    
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(FadeOut());
    }

    // Update is called once per frame
    void Update()
    {
        Move();
    }
    private void Move()
    {
        transform.Translate(Vector2.up*moveSpeed*Time.deltaTime);
    }
    public IEnumerator FadeOut()
    {
        float startA=text.color.a;
        float rate=1.0f/lifeTime;
        float progress=0.0f;
        
        while (progress < 1.0f)
        {
            Color temp = text.color;
            temp.a = Mathf.Lerp(startA, 0, progress);
            text.color = temp;
            progress += rate * Time.deltaTime;
            yield return null;
        }
        Destroy(gameObject);
    }
}
